package com.zc.controller;

/**
 * @description:
 * @author: cong
 * @create: 2024/10/30
 */

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @GetMapping("/test")
    @SentinelResource(value = "test", blockHandler = "block")
    public String test(){
        return "test";
    }

    @GetMapping("/call/{name}")
    // blockHandler()方法的参数和call方法参数一致
    @SentinelResource(value = "call", blockHandler = "fallback")
    public String call(@PathVariable("name") String name){
        return name;
    }

    public String fallback(String name, BlockException e) {
        return name + "fallback";
    }


    public String block(BlockException e) {
        return "block";
    }
}
